package com.mapper;

import com.entity.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ArticleMapper {
    /**
     * 查询所有文章
     * @return
     */
    @Select("select * from article")
    List<Article> findAllArticle();

    /**
     * 分页查询
     * @param pageNum 第rows页
     * @param offset 页条数
     * @return
     */
    @Select("select * from article ORDER BY art_id LIMIT #{pageNum}, #{offset}")
    List<Article> findActiclePage(@Param("pageNum") int pageNum, @Param("offset") int offset);


    /**
     * 根据ID查询文章
     * @param id 文章ID
     * @return
     */
    @Select("select * from article where art_id =#{id}")
    Article findArticleById(@Param("id") int id);

    /**
     * 根据文章名称模糊查询文章
     * @param title 文章名
     * @return
     */
    @Select("select * from article where art_title like \'%${title}%\'")
    List<Article> findArticleByName(@Param("title")String title);

    /**
     * 查询总文章数
     * @return
     */
    @Select("select count(*) from article")
    int count();

    @Insert("insert into article(art_title,art_author,art_create_time,art_context,art_tag) value(#{art_title},#{art_author},#{art_create_time},#{art_context},#{art_tag})")
    int addArticle(Article article);

    //根据文章id删除删除文章
    @Delete("delete from article where art_id =#{id}")
    int delArticleById(@Param("id")int id);

    //根据文章ID更改文章内容(不包括tag)
    @Update("update article set art_title=#{title},art_context=#{context},art_update_time=#{update_time} where art_id = #{id}")
    int updateArticleById(@Param("title") String title, @Param("context")String context, @Param("update_time")String update_time, @Param("id")int id);






}
